package stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class wordStreamTest {

    public static void main(String[] args) {

        String[] arrayOfWords = {"Goodbye", "World"};

        List<String> words = new ArrayList<>();
        words.add("Goodbye");
        words.add("World");

        List<String[]> list = words.stream().map(word -> word.split("")).distinct().collect(toList());
        System.out.println(list);


        Stream<String[]> stream1 = words.stream().map(word -> word.split(""));
        System.out.println(stream1);

        Stream<String> stream = Arrays.stream(arrayOfWords);
        Stream<Stream<String>> distinct = stream1.map(Arrays::stream).distinct();


        System.out.println(stream1.map(Arrays::stream).distinct().collect(toList()));
        //--------正确的做法----------
        Stream<String[]> stream2 = words.stream().map(word -> word.split(""));
        List<String> list1 = stream2.flatMap(aa -> {
            System.out.println(aa + "流中元素");
            return Arrays.stream(aa);
        }).distinct().collect(toList());
        System.out.println(list1);


        //拼接
//        String result = "";
//        words.stream().map(word -> result += word)

    }

}
